package ctd.dome;

import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

public class StringBufferWithStringBuilder implements Serializable{

    private static final long serialVersionUID = 8060356201598287189L;

    public static void testString() {
        long start = System.currentTimeMillis();
        String str = null;
        for (int i = 0; i < 50000; i++) {
            str = str + i + ",";
        }
        System.out.println("String耗时:"+(System.currentTimeMillis() - start));
    }

    public static void testStringBuffer() {
        long start = System.currentTimeMillis();

        StringBuffer sbuf = new StringBuffer();
        for (int i = 0; i < 50000; i++) {
            sbuf.append(i + ",");
        }
        System.out.println("StringBuffer耗时:"+(System.currentTimeMillis() - start));
    }

    public static void testStringBulider() {
        long start = System.currentTimeMillis();

        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < 50000; i++) {
            builder.append(i + ",");
        }
        System.out.println("StringBuilder耗时:"+(System.currentTimeMillis() - start));
    }

    public static void main(String[] args) {
        /*testString();
        testStringBuffer();
        testStringBulider();*/

        int n= StringUtils.countMatches("aaaaabbbbbcccccc","c");
        System.out.println("n="+n);
    }



}